﻿<template>
  <a-modal
    title="新增领料单"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
		<a-form :form="form">
        <a-form-item label="事务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入事务类型" v-decorator="['moveType']" />
        </a-form-item>
        <a-form-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入单据编号" v-decorator="['no']" />
        </a-form-item>
        <a-form-item label="领用项目号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入领用项目号" v-decorator="['wBSElementcode']" />
        </a-form-item>
        <a-form-item label="领料部门" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入领料部门" v-decorator="['benefitingDepartcode']" />
        </a-form-item>
        <a-form-item label="受益部门" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入受益部门" v-decorator="['costCenterID']" />
        </a-form-item>
        <a-form-item label="客户" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入客户" v-decorator="['fI_Client_Analysis_H']" />
        </a-form-item>
        <a-form-item label="是否公司间交易" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-switch v-decorator="['isInnerCompany', { valuePropName: 'checked' }]" />
        </a-form-item>
        <a-form-item label="领料人" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入领料人" v-decorator="['pickerID']" />
        </a-form-item>
        <a-form-item label="仓储中心" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入仓储中心" v-decorator="['warehouseCentername']" />
        </a-form-item>
        <a-form-item label="公司" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入公司" v-decorator="['companyname']" />
        </a-form-item>
        <a-form-item label="施工队" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入施工队" v-decorator="['constructionTeamID']" />
        </a-form-item>
        <a-form-item label="单据状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="请选择单据状态" v-decorator="['orderStatus', {rules: [{ required: true, message: '请选择单据状态！' }]}]">
            <a-select-option v-for="(item,index) in orderStatusData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    WmsTakeMaterialOrderAdd
  } from '@/api/modular/main/WmsTakeMaterialOrderManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        orderStatusData: [],
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
        this.$nextTick(() => {

        });
        const orderStatusOption = this.$options
        this.orderStatusData = orderStatusOption.filters['dictData']('order_statusenum')
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            if(values.isInnerCompany){
              values.isInnerCompany = 1
            }else{
              values.isInnerCompany = 2
            }
            WmsTakeMaterialOrderAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
